///PHILOTES Source Code.  (C)2012 PhiloLabs
#pragma once

#ifndef __GpuProgramUsage_H__
#define __GpuProgramUsage_H__

#include "OgrePrerequisites.h"
#include "OgreGpuProgram.h"


namespace Ogre 
{
	class Pass;

	
	
	
	class _OgreExport GpuProgramUsage : public Resource::Listener, public MemAlloc_Resource
    {
    protected:
        GpuProgramType mType;
		Pass* mParent;
        // The program link
        GpuProgramPtr mProgram;

        /// program parameters
        GpuProgramParametersSharedPtr mParameters;
		
		/// Whether to recreate parameters next load
		bool mRecreateParams;

		void recreateParameters();

    public:
        
        GpuProgramUsage(GpuProgramType gptype, Pass* parent);

		
		GpuProgramUsage(const GpuProgramUsage& rhs, Pass* newparent);

		~GpuProgramUsage();

        
        GpuProgramType getType(void) const { return mType; }

		
		void setProgramName(const String& name, bool resetParams = true);
		
        void setProgram(GpuProgramPtr& prog);
		
        const GpuProgramPtr& getProgram() const { return mProgram; }
		
        const String& getProgramName(void) const { return mProgram->getName(); }

        
        void setParameters(GpuProgramParametersSharedPtr params);
        
        GpuProgramParametersSharedPtr getParameters(void);

        /// Load this usage (and ensure program is loaded)
        void _load(void);
        /// Unload this usage 
        void _unload(void);

		// Resource Listener
		void unloadingComplete(Resource* prog);
		void loadingComplete(Resource* prog);

    };
	
	
}
#endif
